#pragma once


class CGTDTreeCtrl;
class TreeItemImpl;
class CTreeCtrlItem
{
public:
	CTreeCtrlItem():m_ctrl(NULL),m_hItem(NULL){} 
	CTreeCtrlItem(CGTDTreeCtrl* ctrl,HTREEITEM hItem):m_ctrl(ctrl),m_hItem(hItem){}

	void RemoveAllChild();
	CTreeCtrlItem GetFirstChild()const;
	CTreeCtrlItem GetNextSibling()const;
	CTreeCtrlItem GetParent()const;
	CTreeCtrlItem GetPreOrderNext()const; //
	CTreeCtrlItem GetPreOrderEnd()const;

	void SetImage(int nImage, int nSelImage);
	void SetExpandImage(int nImage);
	void SetState(int iState);
	void SetText(const CString& text);
	CString GetText()const;	

	void SetImpl(TreeItemImpl * pImpl);
	TreeItemImpl* GetImpl()const;

	
	DWORD_PTR GetItemData()const;
	
	CTreeCtrlItem GetRoot()const;
	static CTreeCtrlItem GetRoot(CGTDTreeCtrl& tree);

	
	CTreeCtrlItem findItemWithData(DWORD_PTR d)const ; //find the item with the data recursively;
	

	CTreeCtrlItem AddChild(const CString& strNode,HTREEITEM HAfter  = TVI_LAST);

	void Expand();
	void Delete();

	operator bool () const { return IsValid(); }
	virtual bool IsValid()const{ return NULL!=m_hItem && m_ctrl!=NULL; }
public:
	CGTDTreeCtrl* m_ctrl;
	HTREEITEM m_hItem;
};

#define TREEIREM_CONVERSION_DEF(TCLASS,PCLASS) TCLASS(CGTDTreeCtrl* ctrl,HTREEITEM hItem):PCLASS(ctrl,hItem){}\
	TCLASS(const CTreeCtrlItem& item):PCLASS(item){} \
	TCLASS& operator=(const PCLASS& item){ m_hItem = item.m_hItem; return *this; } 
	


